package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumYn;
import com.cw.jeeyt.service.bo.system.SystemAdsBo;
import com.cw.jeeyt.dao.model.system.SystemAdsDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 轮播广告转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemAdsConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemAdsBo do2Bo(SystemAdsDo model) {
        if (model == null) {
            return null;
        }
        String isPublicCn = StringUtil.isNotBlank(model.getIsPublic()) ? EnumYn.find(model.getIsPublic())
            .getDescription() : "";
        SystemAdsBo bo = new SystemAdsBo();
        bo.setId(model.getId());
        bo.setAdsCode(model.getAdsCode());
        bo.setAdsName(model.getAdsName());
        bo.setAdsUrl(model.getAdsUrl());
        bo.setIsPublic(model.getIsPublic());
        bo.setIsPublicCn(isPublicCn);
        bo.setPublicTime(model.getPublicTime());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemAdsDo bo2Do(SystemAdsBo bo) {
        if (bo == null) {
            return null;
        }
        SystemAdsDo model = new SystemAdsDo();
        model.setId(bo.getId());
        model.setAdsCode(bo.getAdsCode());
        model.setAdsName(bo.getAdsName());
        model.setAdsUrl(bo.getAdsUrl());
        model.setIsPublic(bo.getIsPublic());
        model.setPublicTime(bo.getPublicTime());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemAdsBo> doList2BoList(List<SystemAdsDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemAdsConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemAdsDo> boList2DoList(List<SystemAdsBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemAdsConverter::bo2Do));
    }
}
